package com.base.cn.platform.os.service.course.material;

import com.base.cn.platform.os.entity.course.material.CouMaterial;
import com.base.cn.platform.os.entity.course.material.CouMaterialCondition;
import com.base.cn.platform.os.service.FeignAuthConfig;
import com.base.cn.platform.os.service.course.CourseBaseService;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 素材接口
 *
 * @author s.li
 * @create 2018-04-19-19:31
 */
@FeignClient(name = CourseBaseService.appName,configuration = FeignAuthConfig.class)
public interface CouMaterialService extends CourseBaseService {

    /**
     * 验证素材的播放码是否存在
     * @param condition 查询条件
     * @return Map<String,Object>
     */
    @RequestMapping(contextPath + "/checkingMaterialCode")
    Map<String,Object>  checkingMaterialCode(@RequestBody CouMaterialCondition condition);

    /**
     * 查询素材数量
     * @param condition 查询条件
     * @return 数量
     */
    @RequestMapping(contextPath + "/materialCount")
    BigDecimal count(@RequestBody Map<String, Object> condition);
    /**
     * 保存素材数据
     * @param couMaterial 素材对象
     * @return Map<String,Object>
     */
    @RequestMapping(contextPath + "/saveMaterial")
    Map<String,Object> saveMaterial(@RequestBody Map<String, Object> couMaterial);

    /**
     * 分页查询素材数据
     * @param couMaterialCondition 查询条件对象
     * @param currentPage 当前页码
     * @param setSubjectData
     * @param setTeacherData
     * @return PageInfo<CouMaterial>
     */
    @RequestMapping(contextPath + "/findMaterialPage")
    Map<String,Object> findMaterialPage(@RequestBody Map<String, Object> couMaterialCondition,
                                        @RequestParam("currentPage") int currentPage,
                                        @RequestParam("setSubjectData") boolean setSubjectData,
                                        @RequestParam("setTeacherData") boolean setTeacherData);

    /**
     * 多条件查询素材数据列表
     * @param condition 查询条件
     * @param setSubjectData
     * @param setTeacherData
     * @return List<CouMaterial>
     */
    @RequestMapping(contextPath + "/findMaterialList")
    List<Map<String,Object>> findMaterialList(@RequestBody Map<String, Object> condition,
                                              @RequestParam("setSubjectData") boolean setSubjectData,
                                              @RequestParam("setTeacherData") boolean setTeacherData);

    /**
     * 通过多条件查询素材Mpa
     * @param condition 查询条件
     * @param setSubjectData
     * @param setTeacherData
     * @return Map<BigDecimal,CouMaterial>
     */
    @RequestMapping(contextPath + "/findMaterialToIdMap")
    Map<BigDecimal,Map<String,Object>> findMaterialToIdMap(@RequestBody Map<String, Object> condition,
                                                           @RequestParam("setSubjectData") boolean setSubjectData,
                                                           @RequestParam("setTeacherData") boolean setTeacherData);

    /**
     * 通过ID，查询素材对象
     * @param id ID
     * @param setSubjectData
     * @param setTeacherData
     * @return
     */
    @RequestMapping(contextPath + "/findMaterialById")
    Map<String,Object> findMaterialById(@RequestParam("id") BigDecimal id,
                                        @RequestParam("setSubjectData") boolean setSubjectData,
                                        @RequestParam("setTeacherData") boolean setTeacherData);

    /**
     * 通过ID串，查询素材列表
     * @param ids ID串
     * @param setSubjectData
     * @param setTeacherData
     * @return
     */
    @RequestMapping(contextPath + "/findMaterialByIds")
    List<Map<String,Object>> findMaterialByIds(@RequestParam("ids") String ids,
                                               @RequestParam("setSubjectData") boolean setSubjectData,
                                               @RequestParam("setTeacherData") boolean setTeacherData);

    /**
     * 通过ID串，查询素材Map
     * @param ids 尖串
     * @param setSubjectData
     * @param setTeacherData
     * @return
     */
    @RequestMapping(contextPath + "/findMaterialByIdsToMap")
    Map<BigDecimal,Map<String,Object>> findMaterialByIdsToMap(@RequestParam("ids") String ids,
                                                              @RequestParam("setSubjectData") boolean setSubjectData,
                                                              @RequestParam("setTeacherData") boolean setTeacherData);

    /**
     * 修改素材状态
     * @param materialIds 素材ID串，多个ID以“,”隔开
     * @param status 状态，1未发布，2已发布，3删除
     * @return Map<String,Object>
     */
    @RequestMapping(contextPath + "/updateMaterialStatus")
    Map<String,Object> updateMaterialStatus(@RequestParam("materialIds") String materialIds,
                                            @RequestParam("status") int status);

    /**
     * 修改素材浏览/播放状态
     * @param materialIds 素材ID串，多个ID以“,”隔开
     * @param status 状态，1正常，2冻结
     * @return Map<String,Object>
     */
    @RequestMapping(contextPath + "/updateMaterialPlayStatus")
    Map<String,Object> updateMaterialPlayStatus(@RequestParam("materialIds") String materialIds,
                                                @RequestParam("status") int status);

    /**
     * 查询今日直播素材
     *
     * @param userId
     * @return
     */
    @RequestMapping(contextPath + "/listTodayMaterialLive")
    Map<String,Object> listTodayMaterialLive(@RequestParam("userId") BigDecimal userId);

    /**
     * 下载导入模板
     * @param materialType 素材类型，视频/音频
     * @param subjectIds 专业ID串
     * @return 返回模板文件
     * @throws Exception
     */
    @RequestMapping(contextPath + "/downloadMaterialTemplate")
    ResponseEntity<byte[]>  downloadMaterialTemplate(@RequestParam("materialType") String materialType,
                                                     @RequestParam("subjectIds") String subjectIds,
                                                     @RequestParam(value = "playType", required = false) String playType)throws Exception;

    /**
     * 执行导入素材文件
     * @param file 素材内容文件
     * @return
     */
    @RequestMapping(value = contextPath + "/uploadMaterial", method = {RequestMethod.POST}, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    Map<String,Object> uploadMaterial(@RequestPart(value = "file") MultipartFile file,
                                      @RequestParam("userId") BigDecimal userId);


    /**
     * 获取每日直播待办事项
     * @param start
     * @param end
     * @return
     */
    @RequestMapping(contextPath + "/findBacklogLiveList")
    List<Map<String, Object>>findBacklogLiveList(@RequestParam("start") String start, @RequestParam("end") String end);

    /**
     * 查询素材
     * @param whereSql
     * @return
     */
    @RequestMapping(contextPath + "/findCouMaterialBySql")
    CouMaterial findCouMaterialBySql(@RequestParam("whereSql") String whereSql);
}
